package com.lanou.zhihu.service.impl;

import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.mapper.UserMapper;
import com.lanou.zhihu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by QuChao on 2018/11/2.
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User personal_information(String username) {
        User user1 = userMapper.personal_information(username);
        return user1;
    }

    @Override
    public User login(String username, String password) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        User user = userMapper.login(map);
        return user;
    }


    @Override
    public User changePassword(String username, String phone) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("phone", phone);
        return userMapper.changePassword(map);

    }

    @Override
    public void register(String username, String password, String phone) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        map.put("phone", phone);
        userMapper.register(map);
    }

    @Override
    public User register1(Integer id) {
        return userMapper.register1(id);
    }

    @Override
    public Integer change(String username, String phone) {
        Map<String, Object> map = new HashMap<>();
        map.put("username", username);
        map.put("phone", phone);
        return userMapper.change(map);
    }

    @Override
    public boolean changepass(int id, String password) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("password", password);
        int a = userMapper.changepass(map);
        if (a == 0) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public void modifyThePicture(Integer id, String filePath) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("filePath", filePath);
        userMapper.modifyThePicture(map);
    }

    @Override
    public User findById(Integer id) {
        User user = userMapper.findById(id);
        return user;
    }
}
